﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using Labthink.PCSoft.UniversalHost4.Model;
using Labthink.PCSoft.UniversalHost4.Utility;

namespace Labthink.PCSoft.UniversalHost4.Instrument.Converters
{
    public class SelfQueryConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is List<FullData> qds)) return parameter;
            var fd = qds.SingleOrDefault(d => d.DataNo == parameter.ToInt());
            if (fd == null) return parameter;
            if (parameter.ToInt() == 190105) return fd.Value;
            var key = fd.LanguageId + fd.Value;
            var lan = Common.LanguagesFromDb.SingleOrDefault(l => l.LanguageId == key);
            if(lan == null) return key;
            //if (Common.SelfQueryLans.ContainsKey(key)) return Common.SelfQueryLans[key];
            return lan.Text;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            return value;
        }
    }
}
